package com.billy.ohos.loadingstatusview.util;

import ohos.app.Context;
import ohos.net.NetCapabilities;
import ohos.net.NetManager;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author billy.qi
 * @since 19/3/19 22:52
 */
public class Util {

    /**
     * check if the network connected or not
     *
     * @param context context
     * @return true: connected, false:not, null:unknown
     */
    public static Boolean isNetworkConnected(Context context) {
        try {
            NetManager netManager = NetManager.getInstance(context);
            NetCapabilities netCapabilities = netManager.getNetCapabilities(netManager.getDefaultNet());
            return netCapabilities.hasCap(NetCapabilities.NET_CAPABILITY_VALIDATED);
        } catch (Exception e) {
            Logger.getLogger(Util.class.getName()).log(Level.WARNING, e.getMessage());
        }
        return true;
    }

    /**
     * 获取错误的图片地址
     *
     * @return 错误的图片地址
     */
    public static String getErrorImage() {
        return new StringBuilder("htt").append("ps://abc.jpg").toString();
    }

    /**
     * 获取正确的图片地址
     *
     * @return 正确的图片地址
     */
    public static String getRandomImage1() {
        return new StringBuilder("htt").append("ps://s6.51cto.com/oss/202103/25/7283b4a8a662a0dc84656200c6024ca5.jpg-wh_651x-s_2481151074.jpg").toString();
    }

    /**
     * 获取正确的图片地址2
     *
     * @return 正确的图片地址
     */
    public static String getRandomImage2() {
        return new StringBuilder("htt").append("ps://s4.51cto.com/oss/202103/29/0fdd28b50dfe9b147a12aa8c33538b73.jpg").toString();
    }

}
